﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;

namespace UI
{
    public class AcOpenServerRaceItem : MonoBehaviour
    {
        public UILabel labTitle;
        public GameObject namePref;
        public SimpleGrid simpleGrid;
        public UISprite titleLogo;
        
        public void SetActivityItem(ActivityItem activityItem,int index)
        {
            labTitle.text = string.Format(TableTextBlo.GetText("di_x_ming"), activityItem.value);

            if(index == 0)
                titleLogo.spriteName = "UI_item_title_xing_zi";
            else if(index == 1)
                titleLogo.spriteName = "UI_item_title_xing_blue";
            else
                titleLogo.spriteName = "UI_item_title_xing_green";

            foreach (var item in simpleGrid.childs)
            {
                Destroy(item);
            }
            simpleGrid.childs.Clear();

            float scale = 0.9f;
            GameObject commonicon = AssetLoad.ResourceManager.Instance.LoadResource("prefab/CommonIcon") as GameObject;
            for (int i = 0; i < activityItem.rewardList.Count; i++)
            {
                //icon
                GameObject obj = Instantiate(commonicon);
                obj.SetActive(true);
                simpleGrid.AddChild(obj);
                obj.transform.localScale = new Vector3(scale, scale, scale);
                obj.GetComponent<CommonIcon>().SetData(activityItem.rewardList[i].id, true, activityItem.rewardList[i].num);

                //name
                //GameObject name = Instantiate(namePref);
                //name.SetActive(true);
                //name.GetComponent<UILabel>().text = TableTextBlo.GetText(CommonMethod.GetObjectNameTextId(activityItem.rewardList[i].id));
                //name.transform.parent = obj.transform;
                //name.transform.localPosition = new Vector3(0, -60, 0);
                //name.transform.localScale = Vector3.one;
            }
        }

    }
}

